package com.carlinfo.back.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class NoLoginBackServlet extends HttpServlet
{
	private Logger logger = LogManager.getLogger() ; 
	
	@Override
	protected void service(HttpServletRequest requset, HttpServletResponse response) throws ServletException, IOException
	{
		logger.info("=NoLoginBackServlet=service=");
		/*	取出信的内容	*/
		String method = requset.getParameter("method");
		logger.info("==method{}==",method);

		if("login".equalsIgnoreCase(method))
		{
			/*	打开登录界面	*/
			this.login(requset,response);
		}else if("loginSubmit".equalsIgnoreCase(method))
		{
			/*	登录提交操作	*/
			this.loginSubmit(requset,response);
		}
	}
	/**
	 * 	打开登录页
	 * @throws IOException 
	 * */
	private void loginSubmit(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{
		logger.info("==loginSubmit==");
		/*	 打开登陆页 */
		String path = request.getContextPath() + "/AdminsBackServlet?method=main";
		/*	客户端跳转 	 */
		response.sendRedirect(path);
	}
	/**
	 * 	打开登录页面
	 * @throws IOException 
	 * @throws ServletException 
	 * */
	private void login(HttpServletRequest requset, HttpServletResponse response) throws ServletException, IOException
	{
		this.logger.info("=login=");
		/*	打开登录页面	/userscenter/WebContent */
		String path = "/WEB-INF/jsp/back/login.jsp";
		/*	服务器端跳转	*/
		requset.getRequestDispatcher(path).forward(requset, response);
	}
}
